package task3

class OrganizationService {

    def clientManager

    boolean transactional = false

    def parseInitialTreeToJson() {
        return clientManager.parseInitialTreeToJson()
    }

    def getNodeInDatabase(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.getNodeInDatabase(paramMap)
    }

    def saveHuman(human, params) {
        def paramMap = makeParamsSerializable(params)
        clientManager.saveHuman(human, paramMap)
    }

    def saveProject(project, params) {
        def paramMap = makeParamsSerializable(params)
        clientManager.saveProject(project, paramMap)
    }

    def saveDepartment(department, params) {
        def paramMap = makeParamsSerializable(params)
        clientManager.saveDepartment(department, paramMap)
    }

    def getErrorMessage(objectFound) {
        return clientManager.getErrorMessage(objectFound)
    }

    def getSuccessMessage() {
        return 'Saved successfully!'
    }

    def getFailureMessage() {
        return 'Not saved!'
    }

    def updateNode(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.updateNode(paramMap)

    }


    def saveNewNode(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.saveNewNode(paramMap)
    }


    def loadNodeData(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.loadNodeData(paramMap)
    }

    def deleteNode(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.deleteNode(paramMap)
    }


    def updateNodeName(params) {
        def paramMap = makeParamsSerializable(params)
        return clientManager.updateNodeName(paramMap)
    }

    def makeParamsSerializable(params) {
        return new HashMap((Map) params)
    }

}
